package com.future.direction.common.bus;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by S on 2018/3/30.
 */

public class EventBusUtils {

    public static void register(Object subscriber) {
        if (!EventBus.getDefault().isRegistered(subscriber)) {
            EventBus.getDefault().register(subscriber);
        }
    }

    public static void unregister(Object subscriber) {
        if (EventBus.getDefault().isRegistered(subscriber)) {
            EventBus.getDefault().unregister(subscriber);
        }
    }

    public static void sendEvent(EventBusEvent event) {
        EventBus.getDefault().post(event);
    }

    public static void sendStickyEvent(EventBusEvent event) {
        EventBus.getDefault().postSticky(event);
    }

    /**
     * 通过code码区分事件类型
     */
    public static final class EventCode {
        public static final int LOGIN_SUCESS = 0x111111;
        public static final int VIDEO_AUDIO_URL = 0x111112;
        public static final int PERSON_UPDATE = 0x111113;
        public static final int PUBLIC_UPDATE = 0x111114;
        public static final int VOICE_UPDATE = 0x111115;
        public static final int PUBLIC_FINISH = 0x111116;
        public static final int MC_UPDATE = 0x111117;
        public static final int VPN_CLOSE = 0x111118;

        // other more
    }

}
